package zzg.study.codec;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import zzg.study.protocol.Packet;
import zzg.study.protocol.PacketCodec;

/**
 * @Classname PacketEncoder
 * @Description netty提供特殊的handle实现编码
 * @Date 2023/12/3 18:51
 * @Author zhuzhenguo
 */
public class PacketEncoder extends MessageToByteEncoder<Packet> {

    @Override
    protected void encode(ChannelHandlerContext ctx, Packet packet, ByteBuf out) {
        // 实现Packet类型对象到二进制数据的转换 --> 要做的就是将Java对象对应字段写到ByteBuf中
        PacketCodec.INSTANCE.encode(out, packet);
    }

}

